package com.hnit.applet.common.model;

import lombok.Builder;

/**
 * @author BridgeBai
 * @Description: 自定义继承mybatisPlus Page对象的page，增加转换页面Page的方法
 * @date 2021/9/9 16:37
 */
@Builder
public class CPage<T> extends com.baomidou.mybatisplus.extension.plugins.pagination.Page<T> {

    public CPage() {
    }

    public CPage(long current, long size) {
        super(current, size);
    }

    public CPage(long current, long size, long total) {
        super(current, size, total);
    }

    public CPage(long current, long size, boolean isSearchCount) {
        super(current, size, isSearchCount);
    }

    public CPage(long current, long size, long total, boolean isSearchCount) {
        super(current, size, total, isSearchCount);
    }

    public Page toPage() {
        Page page = new Page();
        page.setPageNum((int) this.getCurrent());
        page.setPages((int) this.getPages());
        page.setTotal((int) this.getTotal());
        page.setPageSize((int) this.getSize());
        return page;
    }

    /**
     * 分页信息
     *
     * @param pageNum  每页条数
     * @param pages    当前页
     * @param pageSize 总页数
     * @param total    总条数
     *
     */
    public static Page pageInfo(int pageNum, int pages, int pageSize, Long total) {
        Page page = new Page();
        page.setPageNum(pageNum);
        page.setPages(pages);
        page.setTotal(total);
        page.setPageSize(pageSize);
        return page;
    }
}
